function open_dialog(id) {
    var fw = $(document).width().toString().replace("px", "");
    var fh = $(document).height().toString().replace("px", "");
    var container = $("#" + id);
    $(container).height(fh);
    var block = $(container).find(".sp_block");
    $(container).fadeIn("200");
    if (window.pageYOffset == undefined) {
        var B = document.body; //IE 'quirks'
        var D = document.documentElement; //IE with doctype
        D = (D.clientHeight)? D: B;
        window.pageYOffset = D.scrollTop;
    }
    if ($(block).size() > 0) {
        var bw = $(block).width().toString().replace("px", "");
        var bh = $(block).height().toString().replace("px", "") * 1;
        var ml = ((fw - bw) / 2);
        $(block).css({"margin-left":ml + "px"});
        $(block).animate({
            opacity:'1',
            display:'toggle'
        }, 200, function () {
        });
        var posY = window.pageYOffset * 1;
        if (bh > fh) {
            $(container).height((bh + posY + 20) + "px");
        }
    }
    if ($(block).hasClass("no_scroll")) {
        return false;
    }
    $(window).scroll(function () {
        var B = document.body; //IE 'quirks'
        var D = document.documentElement; //IE with doctype
        D = (D.clientHeight)? D: B;
        window.pageYOffset = D.scrollTop;
        $(block).css({
            'marginTop':window.pageYOffset + "px"
        });
    });
    return false;
}

function close_dialog(id) {
    var container = $("#" + id);
    var block = $(container).find(".sp_block");
    var mt = parseInt($(block).height().toString().replace("px", ""));
    $(container).hide();
    return false;
}

function show_message(message) {
    var exists_message = ($("#frm_message").size() == 0) ? false : true;
    if (exists_message) {
        $("#frm_message").remove();
    }
    var block = '<div id="frm_message" class="frame_block">';
    block += '<div class="sp_block">';
    block += '<div class="sp_block_padding">';
    block += '<div class="sp_block_heading">';
    block += '<div class="bl"><strong>Thông báo</strong></div>';
    block += '<div class="right close_button"></div>';
    block += '</div>';
    block += '<div class="sp_block_content" style="padding: 15px; font-size: 14px; line-height: 20px; text-align: center; color: #333">';
    block += '</div>';
    block += '</div>';
    block += '</div>';
    block += '</div>';
    $("body").append($(block));
    open_dialog('frm_message');
    $('#frm_message .sp_block_content').html(message);
    $('#frm_message .close_button').click(function() {close_dialog('frm_message')});
}


